package com.lagou.dao.impl;

import com.lagou.dao.IUserDao;
import com.lagou.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @param
 * @author oyz
 * @version 1.0.4
 * @description: TODO
 * @date 2022/10/23 8:35
 */
public class UserDaoImpl implements IUserDao {
    @Override
    public List<User> findAll() throws IOException {
        InputStream resourceAsStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(resourceAsStream);
        // 默认开启一个事务，但是该事务不会自动提交
        SqlSession sqlSession = build.openSession();
        // 在执行增删改任务操作时，要手动提交事务
        List<User> objects = sqlSession.selectList("com.lagou.dao.IUserDao.findAll");

        return objects;
    }
}
